package lab1_ArrayList;

import static org.junit.Assert.*;

import java.util.ListIterator;

import org.junit.Test;

public class ArrayListTest {
	
	@Test
	public void testAdd() {
		MyArrayList<Integer> myList=new MyArrayList<Integer>();	
		assertTrue(myList.add(5));
		assertTrue(myList.add(7));
		assertTrue(myList.add(13));
		assertEquals(myList.toString(),"5 7 13");
	}
	
	@Test
	public void testIsEmpty() {
		MyArrayList<Integer> myList=new MyArrayList<Integer>();	
		myList.add(5);
		myList.add(7);
		myList.add(13);
		assertFalse(myList.isEmpty());
		myList.clear();
		assertTrue(myList.isEmpty());
	}
	
	@Test
	public void testRemoveObject() {
		MyArrayList<Integer> myList=new MyArrayList<Integer>();	
		myList.add(5);
		myList.add(7);
		myList.add(13);
		assertTrue(myList.removeObject(7));
		assertEquals(myList.toString(), "5 13");
	}
	
	@Test
	public void testRemoveByIndex() {
		MyArrayList<Integer> myList=new MyArrayList<Integer>();	
		myList.add(5);
		myList.add(7);
		myList.add(13);
		assertEquals(myList.removeByIndex(1), (Integer)7);
		assertEquals(myList.toString(), "5 13");
	}
	
	@Test
	public void testSize() {
		MyArrayList<Integer> myList=new MyArrayList<Integer>();	
		myList.add(5);
		myList.add(7);
		myList.add(13);
		assertEquals(myList.size(), 3);
		myList.add(123);
		assertEquals(myList.size(), 4);
	}
	
	@Test
	public void testGet() {
		MyArrayList<Integer> myList=new MyArrayList<Integer>();	
		myList.add(5);
		myList.add(7);
		myList.add(13);
		assertEquals(myList.get(1), (Integer)7);
		assertEquals(myList.get(2), (Integer)13);
	}
	
	@Test
	public void testToString() {
		MyArrayList<Integer> myList=new MyArrayList<Integer>();	
		myList.add(5);
		myList.add(7);
		myList.add(13);
		assertEquals(myList.toString(), "5 7 13");
		myList.add(123);
		assertEquals(myList.toString(), "5 7 13 123");
	}
	
	@Test
	public void testResize() {
		MyArrayList<Integer> myList=new MyArrayList<Integer>();	
		assertTrue(myList.reSize());
	}
	
	@Test
	public void testHasNext() {
		MyArrayList<Integer> myList=new MyArrayList<Integer>();	
		ListIterator<Integer> iterator=myList.listIterator();
		myList.add(5);
		myList.add(7);
		myList.add(13);
		assertTrue(iterator.hasNext());
		iterator.next();
		assertTrue(iterator.hasNext());
		iterator.next();
		assertTrue(iterator.hasNext());
		iterator.next();
		assertFalse(iterator.hasNext());
	}
	
	@Test
	public void testHasPrevious() {
		MyArrayList<Integer> myList=new MyArrayList<Integer>();	
		ListIterator<Integer> iterator=myList.listIterator();
		myList.add(5);
		myList.add(7);
		myList.add(13);
		iterator.next();
		iterator.next();
		iterator.next();
		assertTrue(iterator.hasPrevious());
		iterator.previous();
		assertTrue(iterator.hasPrevious());
		iterator.previous();
		assertTrue(iterator.hasPrevious());
		iterator.previous();
		assertFalse(iterator.hasPrevious());
	}
	
	@Test
	public void testNext() {
		MyArrayList<Integer> myList=new MyArrayList<Integer>();	
		ListIterator<Integer> iterator=myList.listIterator();
		myList.add(5);
		myList.add(7);
		myList.add(13);
		assertEquals(iterator.next(), (Integer)5);
		assertEquals(iterator.next(), (Integer)7);
		assertEquals(iterator.next(), (Integer)13);
	}
	
	@Test
	public void testPrevious() {
		MyArrayList<Integer> myList=new MyArrayList<Integer>();	
		ListIterator<Integer> iterator=myList.listIterator();
		myList.add(5);
		myList.add(7);
		myList.add(13);
		iterator.next();
		iterator.next();
		iterator.next();
		assertEquals(iterator.previous(), (Integer)13);
		assertEquals(iterator.previous(), (Integer)7);
		assertEquals(iterator.previous(), (Integer)5);
	}
	
	@Test
	public void testClear() {
		MyArrayList<Integer> myList=new MyArrayList<Integer>();	
		myList.add(5);
		myList.add(7);
		myList.add(13);
		myList.clear();
		assertTrue(myList.isEmpty());
	}

}
